﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using DAL;
using CMSModel;
using System.Text.RegularExpressions;
namespace BLL
{
    /// <summary>
    ///BBSBLL 的摘要说明
    /// </summary>
    public class BBSBLL
    {
        public void Imort()
        {
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            BBSDAL bbsdal = new BBSDAL();
            foreach (var c in dal.BBSMatching)
            {
                long time = c.CTime == null ? 0 : c.CTime.Value;
                DataTable tb = bbsdal.GeteData(c.BbsId, time);
                if (tb != null && tb.Rows.Count > 0)
                {
                    foreach (DataRow row in tb.Rows)
                    {
                        News news = new News();
                        news.author = row["author"].ToString();
                        news.OutsideUrl = "http://bbs.emoney.cn/thread-" + row["tid"].ToString() + "-1-1.html";
                        var ctemp = long.Parse(row["dateline"].ToString());
                        c.CTime = ctemp > c.CTime ? ctemp : c.CTime;
                        news.ctime = DateTime.Parse("1970-1-1").AddSeconds(double.Parse(row["dateline"].ToString()));
                        news.title = row["subject"].ToString();
                        News_Type nType = new News_Type();
                        nType.ctime = DateTime.Now;
                        nType.NewsTypeId = c.localTypeId;
                        news.News_Type.Add(nType);
                     
                        dal.AddToNews(news);
                    }
                }
            }
            dal.SaveChanges();
        }




    }
}